package com.dswz.utils;

import java.util.UUID;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestUtils {
	public static String getCSESSIONID(HttpServletRequest request, HttpServletResponse response) {
		Cookie[] cookies = request.getCookies();
		if ((cookies != null) && (cookies.length > 0)) {
			Cookie[] arrayOfCookie1;
			int j = (arrayOfCookie1 = cookies).length;
			for (int i = 0; i < j; i++) {
				Cookie cookie = arrayOfCookie1[i];
				if (cookie.getName().equals("CSESSIONID")) {
					return cookie.getValue();
				}
			}
		}
		String csessionid = UUID.randomUUID().toString().replaceAll("-", "");
		Cookie cookie = new Cookie("CSESSIONID", csessionid);
		cookie.setPath("/");
		cookie.setMaxAge(-1);
		response.addCookie(cookie);
		return csessionid;
	}
}